#ifndef COMMON_H
#define COMMON_H
#pragma once

#include <QWidget>
#include <QEventLoop>   // 事件循环
#include <QTimer>       // 时间库
#include <QDebug>
#include <QMessageBox>  // 消息提示
#include <QTcpSocket>   // 网络库
#include <QHostAddress> // ip 地址类

QT_BEGIN_NAMESPACE
namespace Ui {
    class Chat;
    class Widget;
}
QT_END_NAMESPACE

class Chat : public QWidget
{
    Q_OBJECT

public:
    bool connect_to_server;

    explicit Chat(QWidget *parent = nullptr);
    explicit Chat(QTcpSocket* skt, QWidget *parent = nullptr);
    ~Chat();

    QString get_port();

private slots:
    void server_info_slot();
    void on_clear_pushButton_clicked();
    void on_send_pushButton_clicked();

    void closeEvent(QCloseEvent *ev);

private:
    Ui::Chat *chat_ui;

    // 保存链接
    QTcpSocket* chat_socket;

    // 保存端口
    QString ip;
    QString port;
};


class Widget : public QWidget
{
    Q_OBJECT

public:
    Widget(QWidget *parent = nullptr);
    ~Widget();

private slots:
    void on_cancel_pushButton_clicked();
    void on_connect_pushButton_clicked();

    // void tcp_connected();

private:
    Ui::Widget *ui;

    QTcpSocket* socket;

    // 聊天窗口对象
    Chat* chat;
    int only_one_chat;
    bool server_open;
};

#endif // COMMON_H
